//
//  AppDrawer.m
//  Fangmm
//
//  Created by 阮琦 on 16/3/3.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "AppDrawer.h"
#import "MainNavigationViewController.h"
#import "MainIndexViewController.h"
#import "MenuViewController.h"

static DrawerController <DrawerControllerChild, DrawerControllerPresenting> *drawer;

@implementation AppDrawer

+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    @synchronized(self)
    {
        if (drawer == nil)
        {
            drawer = [super allocWithZone:zone];
        }
    }
    return drawer;
}

+ (DrawerController *)sharedDrawer {
    @synchronized(self){
        if(drawer == nil) {
            MenuViewController *menuVC = [[MenuViewController alloc]init];
            MainIndexViewController *mainIndexVC = [[MainIndexViewController alloc] init];
            MainNavigationViewController *mainNavVC= [[MainNavigationViewController alloc]initWithRootViewController:mainIndexVC];
            drawer = [[DrawerController alloc] initWithLeftViewController:menuVC centerViewController:mainNavVC];
        }
    }
    return drawer;
}

+ (DrawerController *)rebuildDrawer {
    @synchronized(self){
        MenuViewController *menuVC = [[MenuViewController alloc]init];
        MainIndexViewController *mainIndexVC = [[MainIndexViewController alloc] init];
        MainNavigationViewController *mainNavVC= [[MainNavigationViewController alloc]initWithRootViewController:mainIndexVC];
        drawer = [[DrawerController alloc] initWithLeftViewController:menuVC centerViewController:mainNavVC];
    }
    return drawer;
}

-(id)copyWithZone:(struct _NSZone *)zone{
    return drawer;
}

@end
